<?php
namespace Plu\Library\Services\Tga\Baoming;

use Plu\Library\Services\ServiceBase;

class CheckService extends ServiceBase {
    static public function nameCheck($name){
		return preg_match('/^[\x7f-\xff]+$/', $name);
    }

    static public function idcardCheck($idcard){
		$id = (string) $idcard;
		if (strlen($id) != 18) {
			return false;
		}
		$id = str_split($id);
		$check_code = strtoupper(array_pop($id));
		$id = array_reverse($id);
		$sum = 0;
		foreach ($id as $key => $value) {
			$w = pow(2, $key + 1) % 11;
			$sum += $value * $w;
		}
		return (str_replace(10, 'X', (12 - $sum % 11) % 11) == $check_code);
    }
    
    static public function telephoneCheck($telephone){
        return preg_match('/^1[3|4|5|7|8]\d{9}$/', $telephone);
    }
    
    static public function qqCheck($qq){
        return preg_match('/^[1-9]\d{4,}$/', $qq);
    }
    
    static public function emailCheck($email){
        return preg_match('/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+\.([a-zA-Z0-9_-])+$/', $email);
    }

    static public function stringCheck($str){
        return is_string($str);
    }

    static public function intCheck($num){
        return is_numeric($num);
    }
}
?>
